import axios from 'axios';
import qs from 'query-string';
import type { DescData } from '@arco-design/web-vue/es/descriptions/interface';

export interface ResultRecord {
  employee_no: number;
  employee: string;
  date: string;
  roster_start_time: string;
  roster_end_time: string;
  clock_in: string;
  clock_out: string;
  role: string;
  work_type: string;
  job: string | null;
  sleepover_allowance_type: string | null;
  sleepover_allowance: string;
  other_leave: boolean;
  lwop: boolean;
  employee_type: string;
  pay_rate: string;
  applied_rules: string;
  is_public_holiday: boolean;
  work_hours: string;
  roster_hours: string;
  weekday: string;
  morning_hours: string;
  afternoon_hours: string;
  night_hours: string;
  shift: string;
  is_split_shift: boolean;
  base_pay: string;
  calculation_process_base_pay: string;
  overtime_pay: string;
  overtime_hours: string;
  calculation_process_overtime_pay: string;
  segmented_shifts_pay: string;
  calculation_process_segmented_shifts_pay: string;
  is_camping: boolean;
  camping_pay: string;
  fort2week_hours: string;
  fort2week_overtime_hours: string;
  fort2week_overtime_pay: string;
}

export interface ResultListRes {
  result: ResultRecord[];
  total_results: number;
}

export interface ResultParams {
  page: number;
  per_page: number;
  employee_no: number | null; // 员工ID
  employee: string; // 员工姓名
  date: string | null; // 工作日期
  clock_in: string | null; // 上班打卡时间
  clock_out: string | null; // 下班打卡时间
  role: string; // 工作角色
  work_type: string; // 工作类型
  other_leave: boolean; // 是否请假
  lwop: boolean; // 是否无薪假
  employee_type: string; // 员工类型
  pay_rate: number; // 基础工资
  is_public_holiday: boolean; // 是否假期
  weekday: string; // 工作日
  shift: string; // 排班
  is_split_shift: boolean; // 是否分班
}

export async function queryResultList(params: ResultParams) {
  console.log('Request Params:', params);
  // try {
  const response = await axios.get('/api/result', {
    params,
    paramsSerializer: (queryParams) => qs.stringify(queryParams),
  });
  console.log('Response Data:', response);
  return response;
}

// 这个是现在的一个接口的四个规则设置
export interface PolicyRecord {
  id: string;
  number: number;
  name: string;
  contentType: 'img' | 'horizontalVideo' | 'verticalVideo';
  filterType: 'artificial' | 'rules';
  count: number;
  status: 'online' | 'offline';
  createdTime: string;
}

export interface PolicyParams extends Partial<PolicyRecord> {
  current: number;
  pageSize: number;
}

export interface PolicyListRes {
  list: PolicyRecord[];
  total: number;
}

export function queryPolicyList(params: PolicyParams) {
  return axios.get<PolicyListRes>('/api/list/policy', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export interface ServiceRecord {
  id: number;
  title: string;
  description: string;
  name?: string;
  actionType?: string;
  icon?: string;
  data?: DescData[];
  enable?: boolean;
  expires?: boolean;
}

export interface RuleRecord {
  id: number;
  comment: string;
  description: string;
  name: string;
  category: string;
  trigger_condition: string;
  required_columns: string[];
  parameters: string;
  priority: string;
  output_column: string[];
  logic: string;
  enabled: boolean;
  regulation_content: string, // 新增字段
}

export function queryInspectionList() {
  return axios.get('/api/list/quality-inspection');
}

export function queryTheServiceList() {
  return axios.get('/api/list/the-service');
}

export function queryRulesPresetList() {
  return axios.get('/api/list/rules-preset');
}

export function queryRulesPresetListNew() {
  return axios.get('/api/rules');
}
